package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.dto.ExportRecordsDTO;
import com.sc.nft.entity.ExportRecords;
import com.sc.nft.entity.req.ExportRecordRpcRequest;
import com.sc.nft.entity.vo.ExportRecordsVO;
import com.sc.nft.mapper.ExportRecordsMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

/**
 * @author 朱梦晨
 * @Description: 导出记录 (sc_export_records)数据DAO
 * @date 2024-07-24
 */
@Slf4j
@Repository
public class ExportRecordsDao extends ServiceImpl<ExportRecordsMapper, ExportRecords> {


    public ExportRecords getByName(String name) {
        LambdaQueryWrapper<ExportRecords> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ExportRecords::getExportName, name);
        return getOne(wrapper);
    }

    public boolean updateStatusById(Long id, Integer status) {
        LambdaUpdateWrapper<ExportRecords> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(ExportRecords::getId, id);
        wrapper.set(ExportRecords::getStatus, status);
        return update(new ExportRecords(), wrapper);
    }


    /**
     * 导出记录列表 Page
     *
     * @return
     */
    public Page<ExportRecordsVO> exportRecordsList(ExportRecordsDTO exportRecordsDTO) {
        Page<ExportRecordsVO> exportRecordsVOPage = baseMapper.exportRecordsList(exportRecordsDTO.toMp(), exportRecordsDTO.getStatus(),
                exportRecordsDTO.getExportName(), exportRecordsDTO.getStartTime(), exportRecordsDTO.getEndTime(), exportRecordsDTO.getCreatorId());
        return exportRecordsVOPage;
    }

    /**
     * 商家导出记录列表
     *
     * @param request
     * @return
     */
    public Page<ExportRecordsVO> exportDaoRecordsList(ExportRecordRpcRequest request) {
        Page<ExportRecordsVO> exportRecordsVOPage = baseMapper.exportDaoRecordsList(request.toMp(), request.getStatus(),
                request.getExportName(), request.getStartTime(), request.getEndTime(), request.getDaoId());
        return exportRecordsVOPage;
    }

}
